home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-15 | 5.5 KB | 125 lines | [TEXT/KAHL] |
- /*
- * pup.ReadMe
- *
- * Copyright © 1990, Michael S. Engber
- */
-
- This code was written with THINK C 4.0. Permission is granted to use and
- redistribute the CDEF and/or the source. Send me any bugs, comments,
- suggestions.
-
- Michael S. Engber
- 2642 Prairie Ave
- Evanston, IL 60201
-
- INTERNET: engber@ils.nwu.edu
- CompuServe: 70007,3505
-
-
- These files provide three things. The first two being of general interest,
- the last is THINK C specific.
-
- 1) a pop-up menu CDEF which you can use. Use ResEdit and Copy it out
- of pupCDEF.rsrc. DON'T use the CDEF in pup.π.rsrc. It's a fake CDEF for use
- in debugging CDEFs (see #3 below)
-
- A pop-up menu CDEF is provided with the communications toolkit and
- its supposed to be part of system 7.0 so this code is for people who:
- - don't have the com toolkit and want pop-menu's now
- - use the com toolkit pup, but need to give out their code.
- (the toolkit license doesn't give permision to re-distribute the CDEF)
-
- I tried to make this as isomorphic to the system 7.0 CDEF as possible so
- minimal changes to your code will be required to switch over. I don't own
- the com toolkit, so I worked from info I got from some of the Apple
- people on comp.sys.mac.programmer. I believe the main difference will be
- that I've taken contrlRfCon away from you and use it to store botRight
- of the pop-up title box. The Apple version plays some games with
- extending the size of the control record to hold this extra info.
-
- 2) an example of CDEF source in C.
-
- 3) an example of how to make a single THINK C project that both defines
- and tests a CDEF. Normally, you'd have to have a CDEF project that
- creates a CDEF resource and a test project that uses that resource, and
- constantly switch between the two. MPW users don't have to hassle with
- this. If you want to play around with my code create a project named pup.π
- which contains MacTraps, pup.c & main.c.
-
- This project won't actually create a CDEF resource. To make the CDEF:
- - create a new project that includes a copy of pup.c (leave out main.c)
- - change CDEFmain() to main()
- - set the project type file type to CDEF
- - build
- Note: the compiled CDEF is in pupCDEF.rsrc so you don't have mess with
- re-compiling my code it unless you want to customize it.
-
-
-
- Using a Pup:
-
- The contrlRect is divided into two parts, the title box and the pop-up box. The
- width of the title box is specified by the value of contrlMax when the control
- is created. The pop-up box gets the rest of the control rectangle. The pop-up
- title is drawn right justified and the pop-up box is drawn left justified. This
- makes it easy to line up rows of pup's as per IM V p. 25. When the currently
- selected item's title is too wide to fit in the pop-up box then it is truncated
- and '…' is appended to it. One difference between my pup's and the other
- implementations I've seen is that my pop-up box width shrinks/grows to snugly
- fit the currently selected item (it looks nicer - have I offended the ATP?).
-
- The menu handle is stored in contrlData. You can freely manipulate the
- menu handle to add/delete/check items, etc.
-
- Use SetCtlValue()/GetCtlValue() to get/set the item number of the currently
- selected pup menu item.
-
- contrlRfCon is used to store botRight of the title box - DON'T CHANGE IT
-
-
- Creating a Pup:
-
- If contrlMin is non-zero it is assumed to be the resource id of a 'MENU'
- resource to use as the pup. If cntrlMin is zero then Unique1ID() is used to
- create a menu id. When there is no 'MENU' rsrc to use (i.e. cntrlMin is an
- invalid id or zero), a new empty menu is created with contrlTitle as the title
- and contrlMin as its id. In either case, after creating the menu cntrMin gets
- reset to 1 so the control will work properly.
-
- contrlMax determines the width of the pop-up title box. After storing this
- info away contrlMax is then reset to 9999 for simplicity. You could try and
- keep it set to the number of items in the menu, but then whenever you add
- or delete menu items you have remember to update it. Since there is know way
- the user can force the control out of range I didn't see any reason to
- complicate things.
-
- If contrlRfCon is non-zero, it is interpreted as a ResType and passed to
- AddResMenu() to initialize the menu. It is then reset to hold botRight of the
- pop-up title box. DO NOT CHANGE contrlRfCon once the control is created (sorry)
-
- contrlValue determines the initially selected item.
-
-
- Two Minor Bugs (if you can fix - please pipe up):
-
- 1)The menu manager draws the menu in the popped state. So it should make use of
- any color specifications in your menu resource. But, my lazy code makes no
- attempt to draw in color.
-
- The proper way to fix this not write more code, but less. If you use the
- menu definition procedure to draw the current item instead of drawing it by
- hand, you can be sure that it's drawn properly. How? By sending it an
- appropriate message. "What message is that?" you ask. Well, I hear that the
- standard MDEF is or will support such a message and it might even get documented
- "if we have time."
-
- 2) When you put a pup in a dialog box it's item number never get's
- returned by ModalDialog(). Why? I don't know. As far as I can tell I've
- done everything right.
-
-
- What's the term pup?
-
- In the Oscar docs the author made reference to a new vastly improved user
- interface with all the "ugly pup menus" removed. It may have been a typo on his
- part, but I kinda like the name pup.